﻿using com.fmtx.IDal;
using com.fmtx.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using fmtx.Framework.Expend;

namespace com.fmtx.Dal
{
    public class PictureTypeServer : BaseServer<PictureType>, IPictureType
    {
        public IList<PictureType> Query(int uid)
        {
            return db.AllList(w=>w.Uid==uid).ToList();
        }

        public IList<PictureType> Query(int size, int cityid, int placeid)
        {
            List<PictureType> res = new List<PictureType>();
            var list = db.AllList();
            if (list != null)
            {
                if (placeid > 0)
                {
                    foreach (var item in list.Where(w => w.PlaceId == placeid).Take(size))
                    {
                        res.Add(item);
                    }
                }
                if (cityid > 0)
                {
                    foreach (var item in list.Where(w => w.CityId == cityid).Take(size))
                    {
                        res.Add(item);
                    }
                }
                foreach (var item in list.Take(size))
                {
                    res.Add(item);
                }
            }
            return res.DistinctBy(d=>d.Id).Take(size).ToList();
        }
    }
}
